#!/bin/bash

VENDOR=lge
DEVICE=hammerhead
OUTDIR=vendor/$VENDOR/$DEVICE
MAKEFILE=$OUTDIR/$DEVICE-vendor-blobs.mk

######################### hammerhead-vendor-blobs.mk ###########################
(cat << EOF) > $MAKEFILE
PRODUCT_COPY_FILES += \\
EOF

LINEEND="\\"
COUNT=`cat blobs.txt | grep -v ^# | grep -v ^$ | wc -l | awk {'print $1'}`
for FILE in `cat blobs.txt | grep -v ^# | grep -v ^$ | sed -e 's#^/system/##g'`; do
    COUNT=`expr $COUNT - 1`
    if [ $COUNT = "0" ]; then
        LINEEND=""
    fi
    if [[ ! "$FILE" =~ ^-.* ]]; then
        FILE=`echo $FILE | sed -e "s/^-//g"`
        echo "    $OUTDIR/proprietary/$FILE:system/$FILE:$VENDOR $LINEEND" >> $MAKEFILE
    fi
done
################################################################################

########################### device-vendor.mk ###################################
(cat << EOF) > $OUTDIR/device-vendor.mk
# Priv Apps
PRODUCT_COPY_FILES += \\
EOF
for FILE in `ls -l priv-app | awk '{printf $9"\n"}' | sed '/^$/d'`; do
    echo "    $OUTDIR/proprietary/app/$FILE:system/priv-app/$FILE:$VENDOR \\" >> $OUTDIR/device-vendor.mk
done

(cat << EOF) >> $OUTDIR/device-vendor.mk

\$(call inherit-product, vendor/$VENDOR/$DEVICE/$DEVICE-vendor-blobs.mk)
EOF
################################################################################

(cat << EOF) > $OUTDIR/BoardConfigVendor.mk
# USE_CAMERA_STUB := false
EOF
################################################################################

(cat << EOF) > $OUTDIR/proprietary/Android.mk
LOCAL_PATH := \$(call my-dir)

ifeq (\$(TARGET_DEVICE),hammerhead)

include \$(CLEAR_VARS)
LOCAL_MODULE := OmaDmclient
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

include \$(CLEAR_VARS)
LOCAL_MODULE := qcrilmsgtunnel
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

include \$(CLEAR_VARS)
LOCAL_MODULE := SprintHiddenMenu
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

include \$(CLEAR_VARS)
LOCAL_MODULE := shutdownlistener
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

include \$(CLEAR_VARS)
LOCAL_MODULE := TimeService
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

include \$(CLEAR_VARS)
LOCAL_MODULE := UpdateSetting
LOCAL_MODULE_OWNER := lge
LOCAL_SRC_FILES := app/\$(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
include \$(BUILD_PREBUILT)

endif
EOF
################################################################################
